package com.jhws.business.alert.controller;



import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.jhws.business.alert.service.ITblServiceDimService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.jhws.common.Page;
import com.jhws.common.PageRoll;


@Controller
@RequestMapping({"/alertctrl","/alert"})
public class AlertCtrl{
	@Resource
	private ITblServiceDimService serviceDim;
	
	@RequestMapping("queryAlarm.x")
	public ModelAndView queryAlarm(HttpServletRequest request,
			Integer page,String createUsr,String type) throws Exception{
		String where="where 1=1 ";
		int pageSize = 20;
		int beginIndex = pageSize*(page-1);
		if(StringUtils.isNotEmpty(createUsr)){
			where = where + " and create_usr like '%" + createUsr +"%' ";
		}
		if(StringUtils.isNotEmpty(type)){
			where = where + " and type = '" + type +"' ";
		}
		
		Page alerts = serviceDim.findTblServiceDim(beginIndex,pageSize,where);
		PageRoll pr = new PageRoll(request, pageSize, page,
				alerts.getTotalNumber());
		
		ModelAndView mv = new ModelAndView();
		mv.addObject("createUsr", createUsr);
		mv.addObject("type", type);
		mv.addObject("pr",pr);
		mv.addObject("tblServiceDims", alerts.getList());
		mv.setViewName("business/serviceDim/alarmQuery");
		return mv;
	}
}
